<script>
  import {login} from '@/api/loginApi.js'
  import {Message} from "element-ui";
  export default {
    name: 'Login',
    data() {
      return {
        formData: {
          username: '',
          password: ''
        },
        loading: false
      }
    },
    methods: {
      submit() {
        this.loading = true
        if (this.formData.username === '' || this.formData.password === '') {
          Message.error('用户名或密码不能为空！')
          this.loading = false
          return;
        }
        login(this.formData,this.$router).then(success => {
          this.loading = false;
        },error => {
          this.loading = false;
        })
      }
    }
  }
</script>
<template>
  <div class="login-container">
    <div class="box">
      <div class="img-box">
        <img src="@/assets/img/13.webp" alt="" />
      </div>
      <div class="log-box">
        <h3>{{ $t('Login.title') }}</h3>
        <input type="text" v-model="formData.username" :placeholder="$t('Login.usernamePlaceHolder')" />
        <input type="password" v-model="formData.password" :placeholder="$t('Login.passwordPlaceHolder')" />
        <el-button :loading="loading" :element-loading-text="$t('Login.loading')"  @click="submit()" class="btn">{{$t('Login.submit')}}</el-button>
      </div>
    </div>
  </div>
</template>

<style scoped>
.login-container {
  width: 100%;
  height: 100%;
  background: url(@/assets/img/33.jpg) no-repeat center center / cover;
  display: flex;
}

.box {
  width: 700px;
  height: 360px;
  background: rgba(255, 255, 255, 0.2);
  margin: auto auto;
  backdrop-filter: blur(10px);
  border-radius: 20px;
  border-left: 1px solid rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
}
.img-box img {
  width: 150px;
  height: 150px;
  border-radius: 50%;
}

.box {
  display: flex;
  justify-content: center;
  align-items: center;
}

.log-box {
  margin-left: 17px;
}

.log-box * {
  display: block;
  height: 36px;
  width: 300px;
  outline: none;
  border-radius: 5px;
  margin-bottom: 8px;
  font-size: 16px;
  border: none;
  text-align: center;
}

.log-box > h3 {
  font-size: 22px;
  font-weight: bolder;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.log-box input {
  background-color: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
}

.log-box input:focus {
  border: 1px solid rgba(255, 255, 255, 0.8);
  color: rgba(255, 255, 255, 0.8);
}

.log-box input::placeholder {
  color: rgba(255, 255, 255, 0.2);
}

.log-box .btn {
  font-weight: bolder;
  color: rgba(255, 255, 255, 0.7);
  background-color: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.log-box .btn:focus {
  background-color: rgba(255, 255, 255, 0.2);
}
.log-box .btn:hover {
  cursor: pointer;
}
</style>
